package huizhi.net;

import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

/**
 * .1、实现文件上传操作，客户端上传一个图片到服务器端
 */
public class ClientTest1 {
    public static void main(String[] args) throws Exception{
        // 连接本机的8888端口
        Socket client = new Socket(InetAddress.getLocalHost(), 8888);
        //获取文件字节输入流
        FileInputStream fileInputStream = new FileInputStream("D:\\CodeAll\\11399.jpg");
        // 从套接字获取字节输出流
        OutputStream outputStream = client.getOutputStream();

        byte[] buffer = new byte[1024];
        int length ;
        while ((length= fileInputStream.read(buffer) )!=-1){
            outputStream.write(buffer,0,length);
        }
        outputStream.close();
        fileInputStream.close();
        client.close();

    }
}
